package battleofthejavasea;

import java.io.FileNotFoundException;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.loaders.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;


/**
 *
 * @author Murata, Saito, Santana
 * Classe que adiciona símbolos do jogo ao cenário:
 * "X" de erros
 * Esferas verdes/vermelhas de acertos
 * e esferas amarelas de áreas em que sondas foram utilizadas. >> não implementadas.
 */
public class BTJSGameSymbols  {

    //Tiro inimigo certeiro no tabuleiro local
    public BranchGroup hitMe(float posX, float posZ) throws FileNotFoundException
    {
        //Branchgroup de retorno
        BranchGroup branchGroup = new BranchGroup();

        //Loader para o objeto
        ObjectFile objectFile = new ObjectFile();
        Scene scene = objectFile.load("hitMe.obj");

        //Transform3D
        Transform3D transform3D = new Transform3D();

        //TransformGroup criado com o objeto transform
        TransformGroup transformGroup = new TransformGroup(transform3D);

        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        transformGroup.addChild(scene.getSceneGroup());
        transform3D.setIdentity();

        //Posição final do objeto
        transform3D.setTranslation(new Vector3d(posX, 0, posZ));

        transformGroup.setTransform(transform3D);

        branchGroup.addChild(transformGroup);
        branchGroup.compile();

        return branchGroup;
    }

    //Tiro inimigo falho no tabuleiro local
    public BranchGroup missedMe(float posX, float posZ) throws FileNotFoundException
    {
        //Branchgroup de retorno
        BranchGroup branchGroup = new BranchGroup();

        //Loader para o objeto
        ObjectFile objectFile = new ObjectFile();
        Scene scene = objectFile.load("missedMe.obj");

        //Transform3D
        Transform3D transform3D = new Transform3D();

        //TransformGroup criado com o objeto transform
        TransformGroup transformGroup = new TransformGroup(transform3D);

        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        transformGroup.addChild(scene.getSceneGroup());
        transform3D.setIdentity();

        //Posição final do objeto
        transform3D.setTranslation(new Vector3d(posX, 0, posZ));

        transformGroup.setTransform(transform3D);

        branchGroup.addChild(transformGroup);
        branchGroup.compile();

        return branchGroup;
    }

    //Tiro falho no painel de tiros.
    public BranchGroup missShot(float posY, float posX) throws FileNotFoundException
    {
        //Branchgroup de retorno
        BranchGroup branchGroup = new BranchGroup();

        //Loader para o objeto
        ObjectFile objectFile = new ObjectFile();
        Scene scene = objectFile.load("missShot.obj");

        //Transform3D
        Transform3D transform3D = new Transform3D();

        //TransformGroup criado com o objeto transform
        TransformGroup transformGroup = new TransformGroup(transform3D);

        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        transformGroup.addChild(scene.getSceneGroup());
        transform3D.setIdentity();

        //Posiciona
        transform3D.setTranslation(new Vector3d(posX, posY, -5));

        transformGroup.setTransform(transform3D);

        branchGroup.addChild(transformGroup);
        branchGroup.compile();

        return branchGroup;
    }

    //Tiro correto no painel de tiros. Na mosca!
    public BranchGroup bullsEye(float posY, float posX) throws FileNotFoundException
    {
        //Branchgroup de retorno
        BranchGroup branchGroup = new BranchGroup();

        //Loader para o objeto
        ObjectFile objectFile = new ObjectFile();
        Scene scene = objectFile.load("bullsEye.obj");

        //Transform3D
        Transform3D transform3D = new Transform3D();

        //TransformGroup criado com o objeto transform
        TransformGroup transformGroup = new TransformGroup(transform3D);

        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        transformGroup.addChild(scene.getSceneGroup());
        transform3D.setIdentity();

        //Posiciona
        transform3D.setTranslation(new Vector3d(posX, posY, -5));

        transformGroup.setTransform(transform3D);

        branchGroup.addChild(transformGroup);
        branchGroup.compile();

        return branchGroup;
    }

    //resultado da sonda no radar
    public BranchGroup sondaResult(float posY, float posX) throws FileNotFoundException
    {
        //Branchgroup de retorno
        BranchGroup branchGroup = new BranchGroup();

        //Loader para o objeto
        ObjectFile objectFile = new ObjectFile();
        Scene scene = objectFile.load("sonda.obj");

        //Transform3D
        Transform3D transform3D = new Transform3D();

        //TransformGroup criado com o objeto transform
        TransformGroup transformGroup = new TransformGroup(transform3D);

        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        transformGroup.addChild(scene.getSceneGroup());
        transform3D.setIdentity();

        //Posiciona
        transform3D.setTranslation(new Vector3d(posX, posY, -5));

        transformGroup.setTransform(transform3D);

        branchGroup.addChild(transformGroup);
        branchGroup.compile();

        return branchGroup;
    }
}
